package com.ruoyi.web.controller.ziran;

import java.util.List;

import com.ruoyi.ziran.domain.ZrDisasterType;
import com.ruoyi.ziran.service.IZrDisasterTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ziran.domain.ZrQuestionBank;
import com.ruoyi.ziran.service.IZrQuestionBankService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自然灾害题库Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@Controller
@RequestMapping("/ziran/zrQuestionBank")
public class ZrQuestionBankController extends BaseController
{
    private String prefix = "ziran/zrQuestionBank";

    @Autowired
    private IZrQuestionBankService zrQuestionBankService;
    @Autowired
    private IZrDisasterTypeService iZrDisasterTypeService;

    //@RequiresPermissions("ziran:zrQuestionBank:view")
    @GetMapping()
    public String zrQuestionBank(ModelMap mmap)
    {
        ZrDisasterType disasterType=new ZrDisasterType();
        List<ZrDisasterType> typeList=iZrDisasterTypeService.selectList(disasterType);
        mmap.put("typeList",typeList);
        return prefix + "/zrQuestionBank";
    }

    /**
     * 查询自然灾害题库列表
     */
    //@RequiresPermissions("ziran:zrQuestionBank:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZrQuestionBank zrQuestionBank)
    {
        startPage();
        List<ZrQuestionBank> list = zrQuestionBankService.selectZrQuestionBankList(zrQuestionBank);
        return getDataTable(list);
    }

    /**
     * 导出自然灾害题库列表
     */
    //@RequiresPermissions("ziran:zrQuestionBank:export")
    @Log(title = "自然灾害题库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZrQuestionBank zrQuestionBank)
    {
        List<ZrQuestionBank> list = zrQuestionBankService.selectZrQuestionBankList(zrQuestionBank);
        ExcelUtil<ZrQuestionBank> util = new ExcelUtil<ZrQuestionBank>(ZrQuestionBank.class);
        return util.exportExcel(list, "自然灾害题库数据");
    }

    /**
     * 新增自然灾害题库
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        ZrDisasterType disasterType=new ZrDisasterType();
        List<ZrDisasterType> typeList=iZrDisasterTypeService.selectList(disasterType);
        mmap.put("typeList",typeList);
        return prefix + "/add";
    }

    /**
     * 新增保存自然灾害题库
     */
    //@RequiresPermissions("ziran:zrQuestionBank:add")
    @Log(title = "自然灾害题库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZrQuestionBank zrQuestionBank)
    {
        return toAjax(zrQuestionBankService.insertZrQuestionBank(zrQuestionBank));
    }

    /**
     * 修改自然灾害题库
     */
    //@RequiresPermissions("ziran:zrQuestionBank:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZrQuestionBank zrQuestionBank = zrQuestionBankService.selectZrQuestionBankById(id);
        ZrDisasterType disasterType=new ZrDisasterType();
        List<ZrDisasterType> typeList=iZrDisasterTypeService.selectList(disasterType);
        mmap.put("typeList",typeList);
        mmap.put("zrQuestionBank", zrQuestionBank);
        return prefix + "/edit";
    }

    /**
     * 修改保存自然灾害题库
     */
    //@RequiresPermissions("ziran:zrQuestionBank:edit")
    @Log(title = "自然灾害题库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZrQuestionBank zrQuestionBank)
    {
        return toAjax(zrQuestionBankService.updateZrQuestionBank(zrQuestionBank));
    }

    /**
     * 删除自然灾害题库
     */
    //@RequiresPermissions("ziran:zrQuestionBank:remove")
    @Log(title = "自然灾害题库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zrQuestionBankService.deleteZrQuestionBankByIds(ids));
    }
}
